package cate.game.play.skill.passive.hero;

import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import cate.game.play.proce.action.ctx.TimeActionCtx;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 自身生命值低于50%时，为自身附加【守御】/n无冷却时间
 *
 * 灵器强化："画疆墨守"触发的生命值提升至70%，触发时额外为全队附加【诗情】
 */
public class 画疆墨守PH extends PassiveHandler {

	private int 血量;

	private int 自身buff;

	private int 全队buff;

	//血量=5000&自身buff=？？&全队buff=？？
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		血量 = args.getInt("血量", 0);
		自身buff = args.getInt("自身buff", 0);
		全队buff = args.getInt("全队buff", 0);
	}

	@Override
	public void parseExt(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		血量 += args.getInt("血量", 0);
		全队buff = args.getInt("全队buff", 全队buff);
	}

	private boolean addBuff;

	@Override
	public void onMoveDone(MoveCtx move, TimeActionCtx action) {
		if (addBuff) {
			return;
		}
		if (skill.owner.isDead()) {
			return;
		}
		if (skill.owner.attr.total().hpCurRate() > 血量) {
			return;
		}
		addBuff = true;
		skill.owner.buff.tryAddByTid(action, 自身buff);
		if (全队buff > 0) {
			for (Fighter fighter : skill.owner.getFightTeam().getFightersAlive()) {
				fighter.buff.tryAddByTid(action, skill.owner, 全队buff);
			}
		}
	}
}
